package com.tich.common.controller;

import com.tich.common.domain.dto.AreaSelectDTO;
import com.tich.common.domain.entity.Area;
import com.tich.common.domain.vo.AreaVO;
import com.tich.common.service.IAreaService;
import com.tich.constant.ResponseMessageConstant;
import com.tich.result.Result;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/area")
public class  AreaController {

    @Autowired
    private IAreaService iAreaService;

    /**
     * 根据typeId查询地区数据
     * @param typeId
     * @return
     * */
    @GetMapping("/selectByTypeId")
    public Result<List<AreaVO>> selectByTypeId(Integer typeId) {
        log.info("根据typeId查询地区数据，typeId：{}", typeId);
        return Result.success(ResponseMessageConstant.QUERY_SUCCESS, iAreaService.selectByTypeId(typeId));
    }

    /**
     * 根据id集合查询地区数据
     * @param areaSelectDTO
     * @return
     * */
    @PostMapping("/selectByIdList")
    public Result<List<AreaVO>> selectByIdList(@Valid @RequestBody AreaSelectDTO areaSelectDTO) {
        log.info("查询数据根据id集合,{}", areaSelectDTO.getIdList());
        return Result.success(ResponseMessageConstant.QUERY_SUCCESS, iAreaService.selectByIdList(areaSelectDTO));
    }

    /**
     * 查询当前地区的子地区
     * @param id
     * @return
     * */
    @GetMapping("/getSonArea")
    public Result<List<AreaVO>> getSonArea(Long id){
        log.info("查询当前地区的子地区,当前地区id:{}", id);
        return Result.success(ResponseMessageConstant.QUERY_SUCCESS, iAreaService.getSonArea(id));
    }

    /**
     * 根据id查询地区
     * @param id
     * @return
     * */
    @GetMapping
    public Area seleteById(Long id){
        log.info("根据id查询地区:{}", id);
        return iAreaService.lambdaQuery().eq(Area::getId, id).one();
    }
}
